﻿
using FacebookXmpp.Parse;

namespace FacebookXmpp.Stanzas
{
    internal class Bind : Stanza
    {
    	public Bind()
    	{
    		ResponseExpectation = Expectation.Low;
			NextResponse = string.Format( @"<iq id=""{0}"" type=""set"" to=""chat.facebook.com""><bind xmlns=""urn:ietf:params:xml:ns:xmpp-bind""><resource>Test</resource></bind></iq>", NextId );
    	}

		internal override StanzaListenCriteria ListenFor
		{
			get { return new StanzaListenCriteria( "iq", "bind", false, StanzaListenCriteria.DefaultResponseTimeMilliseconds * 4 ); }
		}

        public override void ProcessResponse(MessageData recieved)
		{
            Stream.Dashboard.Me = new Person(Stream.Dashboard) 
                { Name = "me", Id = ((MessageData)recieved.Path("bind/jid")).Value.ToString() };
			
			Stream.RemoveHandler( this );
			Stream.AddHandler( new Presence( "online" ) );
        }
    }
}
